/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webanovare.ruzzle.misc;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

/**
 * TrieManager.java is used to be able to use an old Trie tree instead of 
 * creating a new one for every game.
 */
public class TrieManager {
    final private static Map<File, Trie> createdTries = new HashMap<File, Trie>();
    
    public static Trie initTrie(File wordList) throws FileNotFoundException {
        if(TrieManager.isAlreadyLoaded(wordList)) {
            return TrieManager.createdTries.get(wordList);
        } else {
            Trie t = new Trie(wordList);
            TrieManager.createdTries.put(wordList, t);
            return t;
        }
    }
    
    public static boolean isAlreadyLoaded(File wordList) {
        return TrieManager.createdTries.containsKey(wordList);
    }
}
